#ifndef HARDWAREINTERFACE_HPP
#define HARDWAREINTERFACE_HPP

#include <QObject>
#include <QDebug>

#include "datamemoryorganisation.hpp"
#include "qserialdevice/abstractserial.h"
#include "appsettings.hpp"

class HardwareInterface : public QObject
{
Q_OBJECT
public:
    explicit HardwareInterface(DataMemoryOrganisation *dmo, QObject *parent = 0);
    ~HardwareInterface();

    void setSerialPort(QString name);

private:
    enum ReadState { STARTREAD, READPORTA_1, READPORTA_2, READPORTB_1, READPORTB_2, ENDREAD };

    AbstractSerial *serialPort;
    DataMemoryOrganisation *dataMemoryOrganisation;
    AppSettings *settings;
    bool initialized;
    ReadState currentState;
    int readPortA;
    int readPortB;
    const char cr;
    QString readBuffer;

signals:
    void dataWritten(QString data);
    void dataRead(QString data);
    void error(QString device, QString errorString);
    void ready();
    void informationAvailable();

public slots:
    void processSerialPortQuery();
    void processInformation();

private slots:
    void readFromSerialPort();
    void onDsrChanged(bool status);

};

#endif // HARDWAREINTERFACE_HPP
